//
//  HomeData.m
//  DeyiLife
//
//  Created by zxin on 15/6/30.
//  Copyright (c) 2015年 Deyi. All rights reserved.
//

#import "MarketData.h"

@implementation MarketData

DEFINE_SINGLETON_IMPLEMENTATION(MarketData)

- (void)initWithDict:(NSDictionary *)dict {    
    //read data
    NSDictionary *data = [dict objectForKey:@"data"];
    [JSONModel addDatasFromDict:data withModel:@"MMMarketType" forKey:@"typeList" target:self.marketTypes isAppend:NO];
    [JSONModel addDatasFromDict:data withModel:@"MMMarketHeader" forKey:@"lbtList" target:self.marketHeaders isAppend:NO];
    [JSONModel addDatasFromDict:data withModel:@"MMMarketNew" forKey:@"xpList" target:self.marketNew isAppend:NO];
    NSDictionary *zdm = [data objectForKey:@"zdm"];
    [JSONModel addDatasFromDict:zdm withModel:@"MMMarketNew" forKey:@"list" target:self.marketWorth isAppend:NO];
    [JSONModel addDatasFromDict:data withModel:@"MMMarketPai" forKey:@"jpmsList" target:self.marketZero isAppend:NO];
    [JSONModel addDatasFromDict:data withModel:@"MMMarketPai" forKey:@"rqpaimaiList" target:self.marketRenqi isAppend:NO];
    [self writeDataToCache];
}

- (void)writeDataToCache {
    NSMutableDictionary *cacheDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                      self.marketTypes, @"markettypes",
                                      self.marketHeaders, @"marketheaders",
                                      self.marketZero, @"marketzero",
                                      self.marketRenqi, @"marketrenqi",
                                      self.marketNew, @"marketnews",
                                      self.marketWorth, @"marketworths",
                                      nil];
    [[TMCache sharedCache] setObjectWithTimeStamp:cacheDict forKey:@"AllMarketData" block:nil];
}

- (void)readDataFromCache:(NSDictionary *)dict {
    self.marketTypes = [dict valueForKey:@"markettypes"];
    self.marketHeaders = [dict valueForKey:@"marketheaders"];
    self.marketNew = [dict valueForKey:@"marketnews"];
    self.marketWorth = [dict valueForKey:@"marketworths"];
    self.marketZero = [dict valueForKey:@"marketzero"];
    self.marketRenqi = [dict valueForKey:@"marketrenqi"];
}

ARRAY_INIT(marketTypes)
ARRAY_INIT(marketHeaders)
ARRAY_INIT(marketRenqi)
ARRAY_INIT(marketZero)
ARRAY_INIT(marketNew)
ARRAY_INIT(marketWorth)

@end
